package com.winse.java.javasource;

/**
 * Simple statistics information that can be created when parsing a java source
 * code using the {@link de.java2html.javasource.JavaSourceParser}.
 * 
 * @author Markus Gebhard
 */
public class JavaSourceStatistic {
	private int commentLineCount = -1;
	private int lineCount = -1;
	private int codeLineCount = -1;
	private int emptyLineCount = -1;
	private int maxLineLength = -1;
	private int characterCount = -1;
	private String packageName = null;
	private String fileName = null;

	public JavaSourceStatistic() {
		// nothing to do
	}

	/**
	 * Returns the codeLineCount.
	 * 
	 * @return int
	 */
	public int getCodeLineCount() {
		return codeLineCount;
	}

	/**
	 * Returns the commentLineCount.
	 * 
	 * @return int
	 */
	public int getCommentLineCount() {
		return commentLineCount;
	}

	/**
	 * Returns the emptyLineCount.
	 * 
	 * @return int
	 */
	public int getEmptyLineCount() {
		return emptyLineCount;
	}

	/**
	 * Returns the lineCount.
	 * 
	 * @return int
	 */
	public int getLineCount() {
		return lineCount;
	}

	/**
	 * Returns the maxLineLength.
	 * 
	 * @return int
	 */
	public int getMaxLineLength() {
		return maxLineLength;
	}

	/**
	 * Sets the codeLineCount.
	 * 
	 * @param codeLineCount
	 *            The codeLineCount to set
	 */
	public void setCodeLineCount(int codeLineCount) {
		this.codeLineCount = codeLineCount;
	}

	/**
	 * Sets the commentLineCount.
	 * 
	 * @param commentLineCount
	 *            The commentLineCount to set
	 */
	public void setCommentLineCount(int commentLineCount) {
		this.commentLineCount = commentLineCount;
	}

	/**
	 * Sets the emptyLineCount.
	 * 
	 * @param emptyLineCount
	 *            The emptyLineCount to set
	 */
	public void setEmptyLineCount(int emptyLineCount) {
		this.emptyLineCount = emptyLineCount;
	}

	/**
	 * Sets the lineCount.
	 * 
	 * @param lineCount
	 *            The lineCount to set
	 */
	public void setLineCount(int lineCount) {
		this.lineCount = lineCount;
	}

	/**
	 * Sets the maxLineLength.
	 * 
	 * @param maxLineLength
	 *            The maxLineLength to set
	 */
	public void setMaxLineLength(int maxLineLength) {
		this.maxLineLength = maxLineLength;
	}

	/**
	 * Returns the fileName.
	 * 
	 * @return String
	 */
	public String getFileName() {
		return fileName;
	}

	/**
	 * Sets the fileName.
	 * 
	 * @param fileName
	 *            The fileName to set
	 */
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public void clear() {
		maxLineLength = 0;
		lineCount = 0;
		commentLineCount = 0;
		codeLineCount = 0;
		emptyLineCount = 0;
	}

	public String getScreenString(String lineSeparator) {
		StringBuffer result = new StringBuffer();
		
		result.append(" Package: " + toString(packageName) 
				+ "  Filename: " + toString(fileName) + lineSeparator);
		result.append("   Lines total: " + lineCount 
				+ "  Code: " + codeLineCount 
				+ "  Comments: " + commentLineCount
				+ "  Empty: " + emptyLineCount + lineSeparator);
		result.append("   " + characterCount 
				+ " Characters,  Maximum line length: " + maxLineLength);
		
		return result.toString();
	}

	private String toString(Object value) {
		return value == null ? "" : value.toString();
	}

	/**
	 * Returns the characterCount.
	 * 
	 * @return int
	 */
	public int getCharacterCount() {
		return characterCount;
	}

	/**
	 * Sets the characterCount.
	 * 
	 * @param characterCount
	 *            The characterCount to set
	 */
	public void setCharacterCount(int characterCount) {
		this.characterCount = characterCount;
	}

	/**
	 * Returns the packageName.
	 * 
	 * @return String
	 */
	public String getPackageName() {
		return packageName;
	}

	/**
	 * Sets the packageName.
	 * 
	 * @param packageName
	 *            The packageName to set
	 */
	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}

}
